/*package com.osig.ec.web;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.osig.ec.cfca.PaperlessConfig;
import com.osig.ec.entity.EcCustomersign;

import cfca.paperless.client.bean.ChannelBean;
import cfca.paperless.client.bean.FieldBean;
import cfca.paperless.client.bean.MultiDataBean;
import cfca.paperless.client.bean.PdfBean;
import cfca.paperless.client.bean.SealUserInfo;
import cfca.paperless.client.bean.SignLocation;
import cfca.paperless.client.servlet.PaperlessClient;
import cfca.paperless.client.servlet.PaperlessUniteClient;
import cfca.paperless.client.util.Base64;
import cfca.paperless.client.util.IoUtil;
import cfca.paperless.client.util.PaperlessUtil;
import cfca.paperless.client.util.StrategyUtil;

@Controller
@RequestMapping(value = "/cfcaTESTbf")
public class CfcaTestBF {
	@RequestMapping(value = "exportPeoplePdf")
	public  void exportPeoplePdf(String templateCode, EcCustomersign ecCustomersign,
			HttpServletResponse response) {
		try {
			long timeStart = new Date().getTime();// 开始时间

			PaperlessUniteClient clientBean = new PaperlessUniteClient(PaperlessConfig.uniteUrl);
			////////////////////////////////// 合成模板(synthesizeAutoTemplate)///////////////////////////////////
			String fieldBeanListXml = PaperlessUtil.buildFieldBeanListXml(getFieldBeanList());
			String textBeanListXml = "";
			String imageBeanListXml = "";
			clientBean.addSynthesizeAutoTemplateParams(templateCode, fieldBeanListXml, textBeanListXml,
					imageBeanListXml);

			/////////////////////////// 如下为用户1手写签名相关的数据，如果没用用户1此处可以省略/////////////////////////////////////////////////
			byte[] handwritingImage1 = genImage(ecCustomersign.getCustomername());
			// 上面的应该读取不到，这应该是你们服务的地址，是不是转义了
			byte[] handwritingData1 = handwritingImage1;

			List<MultiDataBean> list1 = new ArrayList<MultiDataBean>();
			list1.add(new MultiDataBean(handwritingData1, "handwritingData.dat", "media-id", "0"));// 手写签名数据

			String proofHashAndMultiData1[] = PaperlessUtil.getProofHashAndMultiData(list1);

			SignLocation signLocation = new SignLocation(1, "投资者签章", "R", 10, 0);// r
			// <LocationStyle>
			// 位置风格：上:U；下:D；左:L；右:R；中:C；默认：C，必填

			// z 证件类型
			SealUserInfo sealUserInfo = new SealUserInfo(ecCustomersign.getCustomername(),
					ecCustomersign.getIdentitytype(), ecCustomersign.getIdentityno(),
					ecCustomersign.getMobileInternet(), ecCustomersign.getSignplace(), ecCustomersign.getSignreason());
			String proofSealStrategyXml = StrategyUtil.createProofSealStrategyXml(handwritingImage1, sealUserInfo,
					signLocation, proofHashAndMultiData1[0]);

			/////////////////////////// 以上为用户1的数据/////////////////////////////////////////////////
			String compoundSealStrategyXml = "<List>" + proofSealStrategyXml + "</List>";
			String bizTypeCode = "";// 业务类型，比如：开户、开通网银
			// 下面这个直接写到/home/下

			String outputFilePath = "auto";
			PdfBean pdfBean = new PdfBean("", "a", bizTypeCode, outputFilePath);// 系统自动存储,存储的路径自动生成
			String multiData = "";
			String pdfBeanXml = PaperlessUtil.buildPdfBeanXml(pdfBean);
			clientBean.addCompoundSealAutoPdfParams(pdfBeanXml, multiData, compoundSealStrategyXml);

			/////////////////////////////////////////////////////////////////////////////////////////

			// 操作员编码或者机构号
			String operatorCode = PaperlessConfig.operatorCode;
			// 渠道编码，可以为空
			String channelCode = PaperlessConfig.channelCode;

			byte[] resultData = clientBean.uniteReqAndRes(operatorCode, channelCode);

			String errorRsString = PaperlessUtil.isError(resultData);

			// 处理结果为正常，保存签章后的PDF文件到本地目录下
			if ("".equals(errorRsString)) {
				System.out.println("OK:sealAutoPdf");
				System.out.println(resultData.length);
				System.out.println(outputFilePath);

				IoUtil.write(""+ecCustomersign+".pdf", resultData);
			} else {
				// 处理结果为异常，打印出错误码和错误信息
				System.out.println("NG:sealAutoPdf");
				System.out.println(resultData.length);
				System.out.println(new String(resultData, "UTF-8"));
			}

			long timeEnd = new Date().getTime();// 结束时间
			System.out.println("time:" + (timeEnd - timeStart));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static byte[] genImage(String name) throws Exception {
		try {
			PaperlessClient clientBean = new PaperlessClient(PaperlessConfig.assistUrl);// 无纸化辅助接口的访问URL

			// 操作员编码或者机构号
			String operatorCode = PaperlessConfig.operatorCode;
			// 渠道编码，可以为空
			String channelCode = PaperlessConfig.channelCode;

			// 取得生成的图片文件数据
			byte[] result = clientBean.autoGenerateImage(getImageStrategyXML(name), operatorCode, channelCode);

			String errorRsString = PaperlessUtil.isError(result);

			// 处理结果为正常，保存生成的图片文件到本地目录下
			if ("".equals(errorRsString)) {
				System.out.println("OK:autoGenerateImage");
				System.out.println(result.length);
				return result;
			} else {
				// 处理结果为异常，打印出错误码和错误信息
				System.out.println("NG:autoGenerateImage");
				System.out.println(result.length);
				System.out.println(errorRsString);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	*//**
	 * 生成图片生成策略文件
	 * 
	 * @return
	 *//*
	public static String getImageStrategyXML(String name) {

		StringBuilder imageStrategyXML = new StringBuilder();

		imageStrategyXML.append("<Request>");
		imageStrategyXML.append("<ImageName>").append(name).append("</ImageName>");// 长方形换行字符“##”
		imageStrategyXML.append("<ImageWidth>").append("100").append("</ImageWidth>");// 图片宽
		imageStrategyXML.append("<ImageHeight>").append("30").append("</ImageHeight>");// 图片高
		imageStrategyXML.append("<ImageShape>").append("21").append("</ImageShape>");// 1：方型
		imageStrategyXML.append("<Color>").append("FF0000").append("</Color>"); // 十六进制，默认FF0000
		imageStrategyXML.append("<FontSize>").append("100").append("</FontSize>"); // 字体大小，默认100
		imageStrategyXML.append("</Request>");
		return imageStrategyXML.toString();
	}

	private static List<FieldBean> getFieldBeanList() throws Exception {
		List<FieldBean> fieldBeanList = new ArrayList<FieldBean>();
		return fieldBeanList;
	}

	*//**
	 * 盖章后得pdf
	 * 
	 * @param response
	 *//*
	@RequestMapping(value = "exportPdf")
	public void exportPdf(HttpServletResponse response) {
		try {
			// 无纸化基本接口的访问地址URL
			PaperlessClient clientBean = new PaperlessClient(PaperlessConfig.url);

			/////////////////////////// 如下为加盖机构印章的策略/////////////////////////////////////////////////
			// 确定签章位置
			String keywordb = "恒天 中岩投资 管理有限公司";
			String locationStyleb = "R";
			int offsetXb = 10;
			int offsetYb = 0;
			SignLocation signLocationb = new SignLocation(keywordb, locationStyleb, offsetXb, offsetYb);
			// 只在第12页的相应位置签字
			// signLocationb.setPage(12);
			// 初始化签章企业信息。由签章企业、签章地点、签章理由组成的签章企业信息
			String usernameb = "郑州银行";
			String sealLocationb = "";
			String sealReasonb = "";
			SealUserInfo sealUserInfob = new SealUserInfo(usernameb, sealLocationb, sealReasonb);
			// 印章代码
			String sealCode = "yz201711101645598";
			// 印章密码
			String sealPassword = "123456";
			// 通过印章编码、印章密码、签章者信息、签章地点创建生成签章策略
			String sealStrategyXml = StrategyUtil.createSealStrategyXml(sealCode, sealPassword, sealUserInfob,
					signLocationb);
			// 结合签章策略生成复合签章策略
			String compoundSealStrategyXml = "<List>" + sealStrategyXml + "</List>";

			// 多媒体数据
			String multiData = "";

			// 提取要批量签章的合同pdf文件
			byte[] pdfFile = IoUtil.read(new FileInputStream("D://CFCA/001.pdf"));
			// 文件存放路径，可以为空
			String outputFilePath = "";
			// 业务流水号，可以为空
			String bizSerialNo = "zzbank1234561117890";
			// 业务类型，比如：开户、开通网银。在电子签章后台业务管理-业务类型功能进行设置，可用于对pdf进行分类，可以为空。
			String bizTypeCode = "";
			 创建新的pdfBeanXml 
			PdfBean pdfBean = new PdfBean(Base64.toBase64String(pdfFile), bizSerialNo, bizTypeCode, outputFilePath);
			String pdfBeanXml = PaperlessUtil.buildPdfBeanXml(pdfBean);

			// 通过渠道编码创建新的业务渠道Xml
			String channelBeanXml = new ChannelBean(PaperlessConfig.channelCode).toString();

			// 通过pdfBeanXml、多媒体数据、复合印章策略Xml、柜员、渠道Xml调用接口完成pdf的复合签章
			byte[] resultData = clientBean.compoundSealAutoPdf(pdfBeanXml, multiData, compoundSealStrategyXml,
					PaperlessConfig.operatorCode, channelBeanXml);
			String errorRsString = PaperlessUtil.isError(resultData);
			System.out.println("errorRsString==" + errorRsString);

			// 处理结果为正常，保存签章后的PDF文件到本地目录下
		
				// 处理结果为异常，打印出错误码和错误信息
				System.out.println("NG:sealAutoPdf");
				System.out.println(resultData.length);
				System.out.println(new String(resultData, "UTF-8"));
		

			System.out.println(new String(resultData, "UTF-8"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
*/